package util;

import org.ini4j.Wini;

import java.io.*;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

/**
 * Ini文件的帮助类
 * 提供读取和写入ini
 * 使用ini4j实现
 *
 * @author wyl
 */
public final class IniHelper {

    //获取配置
    public static Map<String, String> readIniFile(String urlPath) throws Exception {
        InputStream in = new FileInputStream(urlPath);
        BufferedReader br = new BufferedReader(new InputStreamReader(in));
        Properties props = new Properties();
        props.load(br);
        Map<String, String> map = new HashMap<>();
        for (Object s : props.keySet()) {
            map.put(s.toString(), props.getProperty(s.toString()));
        }
        return map;
    }

    public static void setIni(String urlPath, String title, String key, String value) throws Exception {
        Wini wini = new Wini(new File(urlPath));
        wini.put(title, key, value);
        wini.store();
    }


}
